﻿
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- saved from url=(0014)about:internet -->
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:mssdk="winsdk" xmlns:script="urn:script" xmlns:build="urn:build" xmlns:MSHelp="http://msdn.microsoft.com/mshelp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="Description" content="The !cs extension displays one or more critical sections or the whole critical section tree."/>
<meta name="MSHAttr" content="PreferredSiteName:MSDN"/>
<meta name="MSHAttr" content="PreferredLib:/library/windows/hardware"/>
<title>!cs</title>

<meta name="MS-HAID" content="r24_exts_general_A_074a8417-eee7-42e0-a69c-636d4732950c.xml"/>


<link rel="STYLESHEET" type="text/css" HREF="../common/backsdk4.css"/>





<style>
html,div { margin: 0; padding: 0;}

body {
	padding: 0px;
	margin: 0px;
	overflow: auto;
	height: 100%;
}

#winchm_template_button{
	float: right;
	width: 93px;
	top: 7px;
	position: relative;
	text-align: right;
	right: 5px;
	height: auto;
}

#winchm_template_top{
	padding: 0px;
	margin: 0px;
	border-bottom: 1px solid #9B9B9B;
	background-color: #B1CEFE;
}

#winchm_template_navigation{
	margin: 0px;
	padding-top: 7px;
	padding-left: 7px;
	padding-bottom: 3px;
	padding-right: 0px;
	font-size: 8.5pt;
	font-family: Arial, Helvetica, sans-serif;
	font-weight: normal;
	color: #585858;
}

#winchm_template_title{
	margin: 0px;
	padding-top: 4px;
	padding-left: 7px;
	padding-bottom: 7px;
	padding-right: 0px;
	font-size: 18px; 
	font-family: Verdana, Geneva, sans-serif;
	color: #363636;
}

#winchm_template_content{
	margin-top: 20px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	width: auto  !important;
	width: 100%;
}

#winchm_template_footer{
	border-width: 1px;
	border-color: #B1CEFE;
	border-top-style: solid;
	margin-top: 15px;
	margin-left: 15px;
	margin-bottom: 20px;
	margin-right: 15px;
	padding-top: 7px;
	padding-left: 0px;
	padding-bottom: 0px;
	padding-right: 0px;
	font-family: arial, helvetica, sans-serif;
	font-size: 8.5pt;
	color: #696969;
	width: auto;
	text-align: left;
}


#winchm_template_container{
	margin: 0px;
	padding: 0px;
	position: static;
	padding-bottom: 3px;
	overflow: auto;
	background-color: #FFFFFF;
}


@media print
{
#winchm_template_container{
	position: static;	
	margin: 0px;
	padding: 5px;
	
	width: auto;
	height: auto;
	overflow: auto;
}
#winchm_template_button{
visibility:hidden;
}
}

#winchm_template_navigation A:link	{text-decoration: none; color:#004080}
#winchm_template_navigation A:visited  {text-decoration: none; color: #004080}
#winchm_template_navigation A:active {text-decoration: none; color: #004080 }
#winchm_template_navigation A:hover {text-decoration: none;color: #0080FF}

A:link	{text-decoration: underline; color:#0033CC}
A:visited  {text-decoration: underline; color: #0033CC}
A:active {text-decoration: underline; color: #0033CC }
A:hover {text-decoration: underline;color: #FF0000;}
</style>
<script type="text/javascript">
function isMobile(){
Agent = window.navigator.userAgent;
if (Agent.indexOf("iPhone")>=1 || Agent.indexOf("iPad")>=1 || Agent.indexOf("iPod")>=1 || Agent.indexOf("Android")>=1){
return true;
}else{
return false;	
}

}
function d_onresize(){
if (window.navigator.userAgent.indexOf("MSIE")>=1){
document.getElementById('winchm_template_container').style.pixelWidth = document.body.offsetWidth - 3;
document.getElementById('winchm_template_container').style.pixelHeight = document.body.offsetHeight - document.getElementById('winchm_template_top').offsetHeight - 4;
}
document.getElementById('winchm_template_container').style.top = document.getElementById('winchm_template_top').offsetHeight + 'px';
}

function d_onbeforeprint(){
document.getElementById('winchm_template_container').style.width = 'auto';
document.getElementById('winchm_template_container').style.height = 'auto';
}

function d_onafterprint(){
d_onresize();
}

if(!isMobile()){

window.onload = d_onresize;
window.onresize = d_onresize;
window.onbeforeprint = d_onbeforeprint;
window.onafterprint = d_onafterprint;

document.write("<style>\n");
document.write("body {overflow: hidden;}\n");
document.write("#winchm_template_container {position: absolute;overflow: auto;top : 0px;right: 0px;bottom: 0px;left: 0px;}\n");
document.write("</style>\n");
}

</script>
</head>
<body><script language="JavaScript" type="text/JavaScript">
function syn(){
if(parent.nav.tree){
 if(parent.nav.tree.loaded){
  parent.nav.tree.selectNode(2232);
 }else{
  setTimeout("syn()",500);
}
  }else{
  setTimeout("syn()",500);
  }}
if(parent!=self){
  setTimeout("syn()",100);
}else{
  parent.location.href = "../../index.htm?page=debugger/_cs.htm";
}
originalOnload = window.onload;
if(originalOnload==null){
window.onload = function(){parent.contentLoaded = true;};
}else{
window.onload = function(){originalOnload();parent.contentLoaded = true;};
}
</script> 


<div id="winchm_template_top">
	<div id="winchm_template_button"><A href="_cpuid.htm" title="Previous topic"><img id="winchm_template_prev" alt="Previous topic" src="../template2/btn_prev_n.gif" border="0"></a><A href="_cxr.htm" title="Next topic"><img id="winchm_template_next" alt="Next topic" src="../template2/btn_next_n.gif" border="0"></a></div>
	<div id="winchm_template_navigation">Help &gt; 
<A href="introduction6.htm">Debugging Tools for Windows (WinDbg, KD, CDB, NTSD)</A> &gt; <A href="debugger_reference.htm">Debugger Reference</A> &gt; <A href="debugger_commands.htm">Debugger Commands</A> &gt; <A href="general_extensions.htm">General Extension Commands</A> &gt; </div>
	<div id="winchm_template_title">!cs</div>
</div>
<div id="winchm_template_container">
	<div id="winchm_template_content"><div id="mainSection"><p>The <b>!cs</b> extension displays one or more critical sections or the whole critical section tree.</p>
<pre class="syntax"><b>!cs </b>[<b>-s</b>] [<b>-l</b>] [<b>-o</b>] 
<b>!cs </b>[<b>-s</b>] [<b>-o</b>] <i>Address</i> 
<b>!cs </b>[<b>-s</b>] [<b>-l</b>] [<b>-o</b>] <i>StartAddress EndAddress</i> 
<b>!cs </b>[<b>-s</b>] [<b>-o</b>] <b>-d</b> <i>InfoAddress</i> 
<b>!cs </b>[<b>-s</b>] <b>-t</b> [<i>TreeAddress</i>] 
<b>!cs -?</b> 
</pre>
<h2><a id="ddk__cs_dbg"></a><a id="DDK__CS_DBG"></a>Parameters</h2>
<p></p>
<dl>
<dt><a id="_______-s______"></a><a id="_______-S______"></a>       <b>-s</b>      </dt>
<dd>
<p>Displays each critical section's initialization stack trace, if this information is available.</p>
</dd>
<dt><a id="_______-l______"></a><a id="_______-L______"></a>       <b>-l</b>      </dt>
<dd>
<p>Display only the locked critical sections. </p>
</dd>
<dt><a id="_______-o______"></a><a id="_______-O______"></a>       <b>-o</b>      </dt>
<dd>
<p>Displays the owner's stack for any locked critical section that is being displayed. </p>
</dd>
<dt><a id="_______Address______"></a><a id="_______address______"></a><a id="_______ADDRESS______"></a>       <i>Address</i>      </dt>
<dd>
<p>Specifies the address of the critical section to display. If you omit this parameter, the debugger displays all critical sections in the current process.</p>
</dd>
<dt><a id="_______StartAddress______"></a><a id="_______startaddress______"></a><a id="_______STARTADDRESS______"></a>       <i>StartAddress</i>      </dt>
<dd>
<p>Specifies the beginning of the address range to search for critical sections.</p>
</dd>
<dt><a id="_______EndAddress______"></a><a id="_______endaddress______"></a><a id="_______ENDADDRESS______"></a>       <i>EndAddress</i>      </dt>
<dd>
<p>Specifies the end of the address range to search for critical sections.</p>
</dd>
<dt><a id="_______-d______"></a><a id="_______-D______"></a>       <b>-d</b>      </dt>
<dd>
<p>Displays critical sections that are associated with DebugInfo. </p>
</dd>
<dt><a id="_______InfoAddress______"></a><a id="_______infoaddress______"></a><a id="_______INFOADDRESS______"></a>       <i>InfoAddress</i>      </dt>
<dd>
<p>Specifies the address of the DebugInfo.</p>
</dd>
<dt><a id="_______-t______"></a><a id="_______-T______"></a>       <b>-t</b>      </dt>
<dd>
<p>Displays a critical section tree. Before you can use the <b>-t</b> option, you must activate <a href="#Bookmark144">Application Verifier</a> for the target process and select the <b>Check lock usage</b> option. </p>
</dd>
<dt><a id="_______TreeAddress______"></a><a id="_______treeaddress______"></a><a id="_______TREEADDRESS______"></a>       <i>TreeAddress</i>      </dt>
<dd>
<p>Specifies the address of the root of the critical section tree. If you omit this parameter or specify zero, the debugger displays the critical section tree for the current process.</p>
</dd>
<dt><a id="_______-_______"></a>       <b>-?</b>      </dt>
<dd>
<p>Displays some Help text for this extension in the <a href="#Bookmark1223">Debugger Command window</a>.</p>
</dd>
</dl>
<h3><a id="DLL"></a><a id="dll"></a>DLL</h3>
<table>
<tr>
<td>
<p><b>Windows 2000</b></p>
</td>
<td>
<p>Unavailable </p>
</td>
</tr>
<tr>
<td>
<p><b>Windows XP and later</b></p>
</td>
<td>
<p>
          Exts.dll
         </p>
</td>
</tr>
</table>
<p> </p>
<h3><a id="Additional_Information"></a><a id="additional_information"></a><a id="ADDITIONAL_INFORMATION"></a>Additional Information</h3>
<p>For other commands and extensions that can display critical section information, see <a href="#Bookmark1405">Displaying a Critical Section</a>. For more information about critical sections, see the Microsoft Windows SDK documentation, the Windows Driver Kit (WDK) documentation, and <i>Microsoft Windows Internals</i> by Mark Russinovich and David Solomon. (These resources may not be available in some languages 

and countries.) </p>
<h2>Remarks</h2>
<p>The <b>!cs</b> extension requires full symbols (including type information) for the process that is being debugged and for Ntdll.dll. If you do not have symbols for Ntdll.dll, see <a href="#Bookmark1500">Installing Windows Symbol Files</a>.</p>
<p>The following examples shows you how to use <b>!cs</b>. The following command displays information about the critical section at address 0x7803B0F8 and shows its initialization stack trace.</p>
<pre class="syntax" xml:space="preserve"><code>0:001&gt; !cs -s 0x7803B0F8
Critical section   = 0x7803B0F8 (MSVCRT!__app_type+0x4)
DebugInfo          = 0x6A262080
NOT LOCKED
LockSemaphore      = 0x0
SpinCount          = 0x0

Stack trace for DebugInfo = 0x6A262080:

0x6A2137BD: ntdll!RtlInitializeCriticalSectionAndSpinCount+0x9B
0x6A207A4C: ntdll!LdrpCallInitRoutine+0x14
0x6A205569: ntdll!LdrpRunInitializeRoutines+0x1D9
0x6A20DCE1: ntdll!LdrpInitializeProcess+0xAE5</code></pre>
<p>The following command displays information about the critical section whose DebugInfo is at address 0x6A262080.</p>
<pre class="syntax" xml:space="preserve"><code>0:001&gt; !cs -d 0x6A262080
DebugInfo          = 0x6A262080
Critical section   = 0x7803B0F8 (MSVCRT!__app_type+0x4)
NOT LOCKED
LockSemaphore      = 0x0
SpinCount          = 0x0</code></pre>
<p>The following command displays information about all of the active critical sections in the current process.</p>
<pre class="syntax" xml:space="preserve"><code>0:001&gt; !cs
-----------------------------------------
DebugInfo          = 0x6A261D60
Critical section   = 0x6A262820 (ntdll!RtlCriticalSectionLock+0x0)
LOCKED
LockCount          = 0x0
OwningThread       = 0x460
RecursionCount     = 0x1
LockSemaphore      = 0x0
SpinCount          = 0x0
-----------------------------------------
DebugInfo          = 0x6A261D80
Critical section   = 0x6A262580 (ntdll!DeferedCriticalSection+0x0)
NOT LOCKED
LockSemaphore      = 0x7FC
SpinCount          = 0x0
-----------------------------------------
DebugInfo          = 0x6A262600
Critical section   = 0x6A26074C (ntdll!LoaderLock+0x0)
NOT LOCKED
LockSemaphore      = 0x0
SpinCount          = 0x0
-----------------------------------------
DebugInfo          = 0x77fbde20
Critical section   = 0x77c8ba60 (GDI32!semColorSpaceCache+0x0)
LOCKED
LockCount          = 0x0
OwningThread       = 0x00000dd8
RecursionCount     = 0x1
LockSemaphore      = 0x0
SpinCount          = 0x00000000
-----------------------------------------
...</code></pre>
<p>The following command displays the critical section tree.</p>
<pre class="syntax" xml:space="preserve"><code>0:001&gt; !cs -t

Tree root 00bb08c0

Level     Node       CS    Debug  InitThr EnterThr  WaitThr TryEnThr LeaveThr EnterCnt  WaitCnt

-----------------------------------------------------------------------------------------------

    0 00bb08c0 77c7e020 77fbcae0      4c8      4c8        0        0      4c8        c        0
 1 00dd6fd0 0148cfe8 01683fe0      4c8      4c8        0        0      4c8        2        0
 2 00bb0aa0 008e8b84 77fbcc20      4c8        0        0        0        0        0        0
    3 00bb09e0 008e8704 77fbcba0      4c8        0        0        0        0        0        0
    4 00bb0a40 008e8944 77fbcbe0      4c8        0        0        0        0        0        0
    5 00bb0a10 008e8824 77fbcbc0      4c8        0        0        0        0        0        0
    5 00bb0a70 008e8a64 77fbcc00      4c8        0        0        0        0        0        0
    3 00bb0b00 008e8dc4 77fbcc60      4c8        0        0        0        0        0        0
    4 00bb0ad0 008e8ca4 77fbcc40      4c8        0        0        0        0        0        0
    4 00bb0b30 008e8ee4 77fbcc80      4c8        0        0        0        0        0        0
    5 00dd4fd0 0148afe4 0167ffe0      4c8        0        0        0        0        0        0
    2 00bb0e90 77c2da98 00908fe0      4c8      4c8        0        0      4c8       3a        0
 3 00bb0d70 77c2da08 008fcfe0      4c8        0        0        0        0        0        0</code></pre>
<p>The following items appear in this <b>!cs -t</b> display: </p>
<ul>
<li>
<p><b>
       InitThr</b> is the thread ID for the thread that initialized the CS.</p>
</li>
<li>
<p><b>
       EnterThr</b> is the ID of the thread that called <b>EnterCriticalSection</b> last time.</p>
</li>
<li>
<p><b>
       WaitThr</b> is the ID of the thread that found the critical section that another thread owned and waited for it last time.</p>
</li>
<li>
<p><b>
       TryEnThr</b> is the ID of the thread that called <b>TryEnterCriticalSection</b> last time.</p>
</li>
<li>
<p><b>
       LeaveThr</b> is the ID of the thread that called <b>LeaveCriticalSection</b> last time</p>
</li>
<li>
<p><b>
       EnterCnt</b> is the count of <b>EnterCriticalSection</b>.</p>
</li>
<li>
<p><b>WaitCnt</b> is the contention count. </p></li></ul></div></div>	
	<div id="winchm_template_footer">Copyright &copy; 2019. All rights 
reserved. (To change the copyright info, just edit it in template.)</div>
</div>

</body>
</html>
